﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SzCourt.Logic.Common;
using SzCourt.Logic.NBL;
using NBearLite;
using SzCourt.Logic.NBL.DBEntities;

namespace SzCourt.Logic.BLL
{
    public class Case : SzCourtLogic
    {
        public pCaseProgressInfo GetCaseInfo(CaseCondition condition)
        {
            pCaseProgressInfo info = null;
            int total = GetTotalRecord(SZCourtColumns.pCaseQuery, SZCourtColumns.pCaseQuery.CaseQueryID
                    , SZCourtColumns.pCaseQuery.CaseName == condition.CaseName
                    && (SZCourtColumns.pCaseQuery.QueryPWD == condition.QueryPWD || SZCourtColumns.pCaseQuery.QueryPWD==""));

            if (total <= 0)
                return info;
            info = NBLData.Select(SZCourtColumns.pCaseProgressInfo)
          .Where(SZCourtColumns.pCaseProgressInfo.CaseName == condition.CaseName)
          .ToSingleObject<pCaseProgressInfo>();
            return info;
        }

        /// <summary>
        /// 当事人列表
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        public List<pParties> GetPartiesList(CaseCondition condition)
        {
            return NBLData.Select(SZCourtColumns.pParties)
                .Where(SZCourtColumns.pParties.CaseName == condition.CaseName)
                .ToList<pParties>();
        }

        /// <summary>
        /// 开庭
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        public List<pCaseCourtInfo> GetCourtList(CaseCondition condition)
        {
            return NBLData.Select(SZCourtColumns.pCaseCourtInfo)
                .Where(SZCourtColumns.pCaseCourtInfo.CaseName == condition.CaseName && SZCourtColumns.pCaseCourtInfo.CourtStatus == 0)
                .ToList<pCaseCourtInfo>();
        }
        /// <summary>
        /// 审理
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        public List<pCaseCourtInfo> GetAlreadyCourtList(CaseCondition condition)
        {
            return NBLData.Select(SZCourtColumns.pCaseCourtInfo)
                .Where(SZCourtColumns.pCaseCourtInfo.CaseName == condition.CaseName && SZCourtColumns.pCaseCourtInfo.CourtStatus == 1)
                .ToList<pCaseCourtInfo>();
        }

    }
    public class CaseCondition
    {
        /// <summary>
        /// 案号名称
        /// </summary>
        public string CaseName { get; set; }

        /// <summary>
        /// 查询密码
        /// </summary>
        public string QueryPWD { get; set; }
    }
    public class CaseProgressInfo
    {
        /// <summary>
        /// 案号
        /// </summary>
        public string CaseName { get; set; }
        /// <summary>
        /// 立案时间
        /// </summary>
        public string FilingDate { get; set; }
        /// <summary>
        /// 结案时间
        /// </summary>
        public string FinalDate { get; set; }
        /// <summary>
        /// 结案方式
        /// </summary>
        public string Settlement { get; set; }
        /// <summary>
        /// 法官
        /// </summary>
        public string PresidingJudge { get; set; }
        /// <summary>
        /// 书记
        /// </summary>
        public string CourtClerk { get; set; }
        /// <summary>
        /// 案由
        /// </summary>
        public string CauseOfAction { get; set; }
        /// <summary>
        /// 开庭状态
        /// </summary>
        public string CourtStatus { get; set; }
    }

    public enum CourtStatus
    {
        /// <summary>
        /// 未开庭
        /// </summary>
        No,
        /// <summary>
        /// 已开庭
        /// </summary>
        Already,
    }
}
